//
//  RootView.m
//  Photograph
//
//  Created by dllo on 15/11/17.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "RootView.h"
#import "SubScrollView.h"

@interface RootView ()

@property (nonatomic, retain) UIScrollView *scrollV;
@property (nonatomic, retain) UIPageControl *pageC;

@end

@implementation RootView

- (void)dealloc
{
    [_scrollV release];
    [_pageC release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubviews];
    }
    return self;
}

- (void)createSubviews
{
    self.backgroundColor = [UIColor whiteColor];

    self.scrollV = [[UIScrollView alloc] initWithFrame:self.frame];
    self.scrollV.contentSize = CGSizeMake(self.frame.size.width * 21, 0);
    self.scrollV.contentOffset = CGPointMake(self.frame.size.width, 0);
    self.scrollV.pagingEnabled = YES;
    [self addSubview:self.scrollV];
    [_scrollV release];


    for (NSInteger i = 0; i < 21; i++) {
//
//        NSString *fileName = nil;
//        if (0 == i) {
//            fileName = @"image19.jpg";
//        } else if (20 == i) {
//            fileName = @"image1.jpg";
//        } else {
//            fileName = [NSString stringWithFormat:@"image%ld.jpg", i];
//        }
    
#warning 方式2 - 通过初始化方法传参
//        SubScrollView *subScrollV = [[SubScrollView alloc] initWithFrame:CGRectMake(self.frame.size.width * i, 0, self.frame.size.width, self.frame.size.height) index: i];
//        [self.scrollV addSubview:subScrollV];
//        [subScrollV release];
        
#warning 方式1 - 属性直接传值:  将SuvScrollView中的ImageV设置为属性,将这里上面的if判断打开,为SubScrollView.ImageV.image传值
        
        
#warning 方式3 - 重写setter方法传值
        SubScrollView *subScrollV = [[SubScrollView alloc] initWithFrame:CGRectMake(self.frame.size.width * i, 0, self.frame.size.width, self.frame.size.height)];
        subScrollV.index = i;
//        [self.scrollV addSubview:subScrollV];
//        [subScrollV release];
        
        
#warning 方式4 - 自定义方法传值
//        [subScrollV imageWithIndex:i];
        [self.scrollV addSubview:subScrollV];
        [subScrollV release];

        
//        UIScrollView *subScrollV = [[UIScrollView alloc] initWithFrame:CGRectMake(self.frame.size.width * i, 0, self.frame.size.width, self.frame.size.height)];
//        [self.scrollV addSubview:subScrollV];
//        [subScrollV release];
        
        
//        UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
//        imageV.image = [UIImage imageNamed:fileName];
//        [subScrollV addSubview:imageV];
//        [imageV release];
        
        
    }
    
    
    

}


@end
